package com.egoonet.service;

import com.egoonet.dao.DepartmentRepository;
import com.egoonet.dao.DepartmentTreeDao;
import com.egoonet.dao.EmployeeRepository;
import com.egoonet.domain.Department;
import com.egoonet.dept.DepartmentTree;
import com.egoonet.dept.Node;
import com.egoonet.domain.Employee;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 *
 * Created by wchi on 2017/4/22.
 */
@Service
@Slf4j
public class DepartmentService {
    @Autowired
    DepartmentRepository departmentRepository;

    @Autowired
    DepartmentTreeDao departmentTreeDao;

    @Autowired
    EmployeeRepository employeeRepository;

    public Node<Department> getRootDepartment(){
        Long rootDepartmentId = 1L;
        DepartmentTree departmentTree = departmentTreeDao.get(rootDepartmentId, true);
        Node<Department> rootNode = departmentTree.getRootElement();
        log.debug("部门树状数据封装完成");
        return rootNode;
    }

    public ObjectNode buildDepartmentJson(){
        JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
        ObjectNode rootNode = nodeFactory.objectNode();

        Node<Department> rootDepartment = getRootDepartment();
        createDepartmentNode(rootDepartment, rootNode);
        return rootNode;
    }

    private void createDepartmentNode(Node<Department> rootDepartment, ObjectNode rootNode) {


    }
}
